package org.tloss.web.editor.model.oper.math;

import javax.xml.bind.annotation.XmlAttribute;

import org.tloss.web.editor.utils.Constants;

public class EntityColumnOperator extends ColumnOperand {
	private String name;

	@XmlAttribute
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Override
	public String getDisplayText() {
		if (name != null && getColumn() != null) {

			return "Entities[" + name + "]." + getColumn().getColumnName();
		} else {
			return "Entities[]";
		}
	}

	@Override
	public String generate(int type, Object[] param) {
		if (Constants.CodeType.JAVA == type) {
			StringBuffer buffer = new StringBuffer();
			buffer.append(name).append(".get(0).").append("get")
					.append(getColumn().getColumnName()).append("()");
			return buffer.toString();
		}
		return super.generate(type, param);
	}

	@Override
	public String getType() {

		return getColumn().getMapping().getType();
	}
}
